package com.example.service.impl;

import com.example.entity.SecKillSku;
import com.example.mapper.SkuMapper;
import com.example.service.SkuService;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

/**
 * (SecKillSku)表服务实现类
 *
 * @author 游家纨绔
 * @since 2023-08-30 12:30:00
 */
@Service("skuService")
public class SkuServiceImpl implements SkuService {

	@Autowired
	private SkuMapper skuMapper;

	@Override
	public SecKillSku queryMinPriceSku(Integer id) {
		return skuMapper.queryMinPriceSku(id);
	}

	@Override
	public List<String> selectColor(Integer spuId) {
		Example example = new Example(SecKillSku.class);
		example.selectProperties("color");
		example.createCriteria().andEqualTo("spuId", spuId);
		List<SecKillSku> secKillSkus = skuMapper.selectByExample(example);
		return secKillSkus.stream().map(SecKillSku::getColor).collect(Collectors.toList());
	}

	@Override
	public SecKillSku changeGoodByColor(Integer spuId, String color) {
		Example example = new Example(SecKillSku.class);
		example.createCriteria().andEqualTo("spuId", spuId).andEqualTo("color", color);
		return skuMapper.selectOneByExample(example);
	}

	@Override
	public SecKillSku selectOne(Integer spuId) {
		return skuMapper.selectByPrimaryKey(spuId);
	}

	@Override
	public SecKillSku selectById(Integer id) {
		return skuMapper.selectOne(SecKillSku.builder().id(id).build());
	}

}
